package ltd.newbee.mall.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ltd.newbee.mall.entity.NewBeeMallOrder;
import ltd.newbee.mall.entity.Sale;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<NewBeeMallOrder> {

    @Select("select c.DATE as d, IFNULL(SUM(t.total_price),0) as sale\n" +
            "from calendar as c  left join tb_newbee_mall_order as t  on c.DATE =date_format(t.pay_time,'%Y-%m-%d') \n" +
            "where (c.DATE between date(now()- interval #{day} day) and date(now()))\n" +
            "group by c.DATE\n" +
            "ORDER BY c.DATE")
    List<Sale> selectNearly_10_days(Integer day);


    /**
     * 根据年份，展示每个月的
     * @param year
     * @return
     */
    @Select("SELECT  date_format(c.DATE,'%Y-%m-%d')  AS d, IFNULL(SUM(total_price),0) as sale \n" +
            "from calendar as c  left join tb_newbee_mall_order as t  on c.DATE =date_format(t.pay_time,'%Y-%m-%d')\n" +
            "WHERE YEAR (c.DATE) = #{year} \n" +
            "GROUP BY MONTH (c.DATE)\n" +
            "ORDER BY MONTH (c.DATE)")
    List<Sale> selectNearly_Month(String year);

}
